<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>申请退货单</title>
    <!--{include file="comm/icheck.tpl"}-->
</head>

<body>
<div class="form-horizontal" style="margin: 10px 10px 60px 10px;">

    <div class="title">
        <h2 class="tac">
            申请退货单
        </h2>
    </div>

    <form id="return_form" onsubmit="return false;">

        <div class="panel panel-default">
            <div class="panel-heading">退货单信息</div>
            <div class="panel-body">

                <div class="form-group">
                    <label class="col-sm-2 control-label">订单号</label>
                    <div class="col-sm-10">
                        <p class="form-control-static"><!--{$bill_array.bill_code}--></p>
                        <input type="hidden" name="bill_no" value="<!--{$bill_array.bill_no}-->"/>
                        <input type="hidden" name="bill_code" value="<!--{$bill_array.bill_code}-->"/>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">运费</label>
                    <div class="col-sm-10">
                        <p class="form-control-static"><!--{$bill_array.deliver_feePaid}--></p>
                    </div>
                </div>



                <div class="form-group">
                    <label for="second_id" class="col-sm-2 control-label"><span class="red">*</span> 退货原因</label>
                    <div class="col-sm-2">
                        <select class="form-control col-sm-2" id="second_id" name="return_reason_id_1" style="width: 200px;margin-right: 10px;">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <label for="third_id" class="col-sm-1 control-label">内容</label>
                    <div class="col-sm-5">
                        <select class="form-control col-sm-2" id="third_id" name="return_reason_id_2" style="width: 200px;">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="return_memo" class="col-sm-2 control-label">问题描述</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" style="width: 470px;height: 90px;" name="return_memo" id="return_memo"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="red">*</span> 商品返回方式</label>
                    <div class="col-sm-10" style="padding-top: 4px;">
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="goods-return-type-square-radio-1" name="goods_return_type" value="1">
                            <label for="goods-return-type-square-radio-1">快递至商家</label>
                        </div>
                        <div class="fl">
                            <input type="radio" class="square-radio" id="goods-return-type-square-radio-2" name="goods_return_type" value="2" checked>
                            <label for="goods-return-type-square-radio-2">上门取件</label>
                        </div>
                    </div>
                </div>

                <div class="form-group hide pick_addr">
                    <label for="pick_province_list" class="col-sm-2 control-label"><span class="red">*</span> 取货地址</label>
                    <div class="col-sm-10">
                        <select class="form-control col-sm-2" id="pick_province_list" name="pick_provinceid" style="width: 150px;margin-right: 10px;">
                            <option value="0">请选择...</option>
                        </select>
                        <select class="form-control col-sm-2" id="pick_city_list" name="pick_cityid" style="width: 150px;margin-right: 10px;">
                            <option value="0">请选择...</option>
                        </select>
                        <select class="form-control col-sm-2" id="pick_county_list" name="pick_countyid" style="width: 150px;">
                            <option value="0">请选择...</option>
                        </select>
                    </div>
                </div>

                <div class="form-group hide pick_addr">
                    <label for="pick_address" class="col-sm-2 control-label">&nbsp;</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="pick_address" name="pick_address" value="<!--{$bill_array.deliver_address}-->" placeholder="取货地址" style="width: 470px;">
                    </div>
                </div>

                <div class="form-group">
                    <label for="custName" class="col-sm-2 control-label"><span class="red">*</span> 联系人姓名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="custName" name="custName" value="<!--{$bill_array.deliver_name}-->" placeholder="联系人姓名" style="width: 150px;">
                    </div>
                </div>

                <div class="form-group">
                    <label for="mobile" class="col-sm-2 control-label"><span class="red">*</span> 手机号码</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="mobile" name="mobile" value="<!--{$bill_array.deliver_mobile}-->" placeholder="手机号码" style="width: 150px;">
                    </div>
                </div>
                <!--{if isset($bill_pay_array) && !empty($bill_pay_array)}-->
                <div class="form-group">
                    <div>
                        <label class="col-sm-2 control-label"> 支付方式：</label>
                        <div class="col-sm-10">
                            <table id="couponTable">
                                <!--{foreach from=$bill_pay_array item=pay}-->
                                <!--{if $pay.type == 1}-->
                                <tr>
                                    <td class="td_input" style="height:35px; width: 790px;">
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payment_method_name}--></p>
                                            <input type="text" class="form-control col-sm-2" name="return_pay[]" value="" placeholder="退货金额" style="width: 150px;">
                                            <p style="color: red;">系统会根据退货商品默认退货金额，也可填写。将在订单结算时减去这部分金额。</p>
                                            <input type="hidden" name="payTypeID[]" value="<!--{$pay.payment_method_id}-->"/>
                                            <input type="hidden" name="payTypeName[]" value="<!--{$pay.payment_method_name}-->"/>
                                            <input type="hidden" name="pay_amount[]" value="<!--{$pay.pay_amount}-->"/>
                                        </div>
                                    <td>
                                </tr>
                                <!--{/if}-->
                                <!--{if $pay.type == 2}-->
                                <tr>
                                    <td class="td_input" style="height:35px; width: 790px;">
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payTypeName}--></p>
                                            <input type="text" class="form-control col-sm-2" name="return_pay[]" value="" placeholder="退货金额" style="width: 150px;">
                                            <p style="color: red;">系统会根据退货商品默认退货金额，也可填写。将在订单结算时减去这部分金额。</p>
                                            <input type="hidden" name="payTypeID[]" value="<!--{$pay.payTypeID}-->"/>
                                            <input type="hidden" name="payTypeName[]" value="<!--{$pay.payTypeName}-->"/>
                                            <input type="hidden" name="pay_amount[]" value="<!--{$pay.pay_amount}-->"/>
                                        </div>
                                    <td>
                                </tr>
                                <!--{/if}-->
                                <!--{if $pay.type == 4}-->
                                <!--{if !in_array($pay.payTypeName,$return_pay_array)}-->
                                <tr>
                                    <td>
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payTypeName}--></p>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div style="margin: 5px;" >
                                                            <input type="checkbox" class="square-radio" id="distribution-checkbox-<!--{$pay.payTypeID}-->" name="balance" value="<!--{$pay.payTypeID}-->">
                                                            <label for="distribution-checkbox-<!--{$pay.payTypeID}-->"><!--{$pay.payTypeName}-->(<!--{$pay.pay_amount}-->)</label>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                            <input type="hidden" name="balance_name[]" value="<!--{$pay.payTypeName}-->"/>
                                            <input type="hidden" name="balance_amount[]" value="<!--{$pay.pay_amount}-->"/>
                                        </div>
                                    </td>
                                </tr>
                                <!--{/if}-->
                                <!--{/if}-->
                                <!--{if $pay.type == 5}-->
                                <!--{if !in_array($pay.payTypeName,$return_pay_array)}-->
                                <tr>
                                    <td>
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payTypeName}--></p>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div style="margin: 5px;" >
                                                            <input type="checkbox" class="square-radio" id="distribution-checkbox-<!--{$pay.payTypeID}-->" name="points" value="<!--{$pay.payTypeID}-->">
                                                            <label for="distribution-checkbox-<!--{$pay.payTypeID}-->"><!--{$pay.payTypeName}-->(<!--{$pay.pay_amount}-->)</label>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                            <input type="hidden" name="points_name[]" value="<!--{$pay.payTypeName}-->"/>
                                            <input type="hidden" name="points_amount[]" value="<!--{$pay.pay_amount}-->"/>
                                        </div>
                                    </td>
                                </tr>
                                <!--{/if}-->
                                <!--{/if}-->
                                <!--{if $pay.type == 6 && $pay.coupon neq ""}-->
                                <tr>
                                    <td>
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payTypeName}--></p>
                                            <table id="coupon_list">
                                                <!--{foreach from=$pay.coupon key=i item=user_coupon}-->
                                                <!--{if !in_array($user_coupon.coupon_code,$return_coupon_array)}-->
                                                <tr>
                                                    <td>
                                                        <div style="margin: 5px;" >
                                                            <input type="checkbox" class="square-radio" id="distribution-checkbox-<!--{$user_coupon.coupon_code}-->" name="coupon_code" value="<!--{$user_coupon.coupon_code}-->">
                                                            <label for="distribution-checkbox-<!--{$user_coupon.coupon_code}-->"><!--{$user_coupon.coupon_name}-->(<!--{$user_coupon.coupon_code}-->)</label>
                                                            <input type="hidden" name="coupon_name[<!--{$user_coupon.coupon_code}-->][]" value="<!--{$user_coupon.coupon_name}-->">
                                                            <input type="hidden" name="coupon_amount[<!--{$user_coupon.coupon_code}-->][]" value="<!--{$user_coupon.amount}-->"/>
                                                        </div>
                                                        <div style="display: none;">
                                                            <input type="checkbox" checked class="square-radio" id="coupon-code-checkbox-<!--{$user_coupon.coupon_code}-->" name="coupon_code_check" value="<!--{$user_coupon.coupon_code}-->">
                                                        </div>
                                                    </td>
                                                </tr>
                                                <!--{/if}-->
                                                <!--{/foreach}-->
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                                <!--{/if}-->
                                <!--{if $pay.type == 7 && $pay.card neq ""}-->
                                <tr>
                                    <td>
                                        <div class="col-sm-10">
                                            <p class="form-control-static col-sm-2"><!--{$pay.payTypeName}--></p>
                                            <table>
                                                <!--{foreach from=$pay.card key=k item=user_card}-->
                                                <!--{if !in_array($user_card.card_no,$return_card_array)}-->
                                                <tr>
                                                    <td>
                                                        <div style="margin: 5px;" >
                                                            <input type="checkbox" class="square-radio" id="distribution-checkbox-<!--{$k}-->" name="card_no" value="<!--{$user_card.card_no}-->">
                                                            <label for="distribution-checkbox-<!--{$k}-->"><!--{$user_card.card_name}-->(<!--{$user_card.card_no}-->)</label>
                                                            <input type="hidden" name="card_name[<!--{$user_card.card_no}-->][]" value="<!--{$user_card.card_name}-->">
                                                            <input type="hidden" name="card_amount[<!--{$user_card.card_no}-->][]" value="<!--{$user_card.deduction}-->"/>
                                                        </div>
                                                        <div style="display: none;">
                                                            <input type="checkbox" checked class="square-radio" id="card-no-checkbox-<!--{$k}-->" name="card_no_check" value="<!--{$user_card.card_no}-->">
                                                        </div>
                                                    </td>
                                                </tr>
                                                <!--{/if}-->
                                                <!--{/foreach}-->
                                            </table>
                                        </div>

                                    </td>
                                </tr>


                                <!--{/if}-->
                            <!--{/foreach}-->
                                <!--{if ($pay.type == 7 && $pay.card neq "") || ($pay.type == 6 && $pay.coupon neq "") || $pay.type == 5 ||  $pay.type == 4}-->
                                <tr>
                                    <td>
                                        <p style="color: red;"> 订单已支付的代金卡、优惠券、余额，勾选后将在退货单审核后全额返还原支付方式中。</p>
                                    </td>
                                </tr>
                                <!--{/if}-->
                            </table>

                        </div>

                    </div>

                </div>
                <!--{/if}-->

            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">退货商品</div>
            <table class="table" id="goods_table">
                <thead>
                <tr>
                        <th width="100">商品编号</th>
                        <th width="*">商品名称</th>
                        <th width="100">规格</th>
                        <th width="100">销售价</th>
                        <th width="100">积分价</th>
                        <th  style="text-align: center; width: 100px;">积分</th>
                        <th width="100">购买数量</th>
                        <th width="100">可提交数量</th>
                        <th width="100">配件费</th>
                        <th width="150">提交数量</th>
                    </tr>
                </thead>

                <tbody>
                <!--{foreach from=$bill_goods_array item=goods}-->
                    <tr>
                        <td style="text-align: center;"><!--{$goods.product_code}--></td>
                        <td class="tal">
                            <!--{$goods.goods_name}-->
                        </td>
                        <td ><!--{$goods.goods_spec}--></td>
                        <td id="price_<!--{$goods.bill_goods_no}-->"><!--{$goods.goods_purchasePrice|string_format:"%.2f"}--></td>
                        <td ><!--{$goods.goods_pointsPrice|string_format:"%.2f"}--></td>
                        <td style="text-align: center;" ><!--{$goods.goods_points}--></td>
                        <td style="text-align: center;" ><!--{$goods.goods_amount}--></td>
                        <td style="text-align: center;" id="use_amount_<!--{$goods.bill_goods_no}-->" ><!--{$goods.goods_amount-$goods.goods_withdrawAmount-$goods.goods_rejectionAmount}--></td>
                        <td id="buyMoney_<!--{$goods.bill_goods_no}-->" style="text-align: center;" ><!--{$goods.buyMoney|string_format:"%.2f"}--></td>
                        <td style="text-align: center;">
                            <img src="/quanliadmin/docroot/images/bag_open.gif" id="addNumber" onclick="bill.addNumber('<!--{$goods.bill_goods_no}-->');" style="cursor: pointer;" >
                            <input type="text" style="width: 38px;text-align: center;" id="input_amount_<!--{$goods.bill_goods_no}-->" name="withdrawAmount[<!--{$goods.bill_goods_no}-->]" value="0" readonly="readonly" autocomplete="off">
                            <img src="/quanliadmin/docroot/images/bag_close.gif" id="reduceNumber" onclick="bill.reduceNumber('<!--{$goods.bill_goods_no}-->');" style="cursor: pointer;" >                    </td>
                    </tr>
                <!--{/foreach}-->
                </tbody>
            </table>
        </div>

    </form>

    <div class="bottom_fixbox">
        <div class="rectbox tac" style="position: relative;">
            <input type="button" class="btn" onclick="bill.save();" value="保存" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭"  />
           <div style="position: absolute;right:25px;top:0px;">
               <span>金额：</span>
               <span class="red" id="return_prices" >0.00</span>
               &nbsp;
               <span>数量：</span>
               <span class="red" id="return_amounts" >0</span>
           </div>
        </div>
    </div>
</div>

<!--{include file='comm/deliver.tpl'}-->

<script type="text/javascript">

$(window).ready(function() {

    $('.square-radio').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional

    });

    if($('#goods-return-type-square-radio-2').is(':checked')){
        $('.pick_addr').removeClass('hide');
    }

    $('#goods-return-type-square-radio-1').on('ifClicked', function() {
        $('.pick_addr').addClass('hide');
    });

    $('#goods-return-type-square-radio-2').on('ifClicked', function() {
        $('.pick_addr').removeClass('hide');
    });

    E.region.init({
        pid: <!--{$bill_array.deliver_provinceid}-->,
        cid: <!--{$bill_array.deliver_cityid}-->,
        ccid: <!--{$bill_array.deliver_countyid}-->
    });

    E.region.init({
        p: 'pick_province_list',
        c: 'pick_city_list',
        a: 'pick_county_list',
        pid: <!--{$bill_array.deliver_provinceid}-->,
        cid: <!--{$bill_array.deliver_cityid}-->,
        ccid: <!--{$bill_array.deliver_countyid}-->
    }, 'pick');

    $("input[name='balance']").on('ifChanged',function(){
        bill.calcAmount();
    });

    $("input[name='points']").on('ifChanged',function(){
        bill.calcAmount();
    });

    $("input[name='coupon_code']").on('ifChanged',function(){
        bill.calcAmount();
    });

    $("input[name='card_no']").on('ifChanged',function(){
        bill.calcAmount();
    });

});

var bill = {

    goods_array : <!--{$bill_goods_array_json}-->,//商品数组
    bill_array : <!--{$bill_array_json}-->,//订单数组

    use_amount_total : <!--{$use_amount_total}--> , //可退货的总数量
    deliver_feePaid : <!--{$bill_array.deliver_feePaid}-->, //运费

    price : 0.00,

    amount : 0,

    identify : <!--{$identify}-->,

    //增加退货 数量
    addNumber : function (bill_goods_no) {

        //输入框内的数量
        var return_amount = parseInt($('#input_amount_' + bill_goods_no).val());

        //可退货的数量
        var use_amount = parseInt($('#use_amount_' + bill_goods_no).text());

        if( return_amount >= use_amount ){
            return;
        }else{
            return_amount++;
            $('#input_amount_' + bill_goods_no).val(return_amount);
        }

        this.amount++;
        this.calcAmount();
    },

    //减少退货 数量
    reduceNumber : function (bill_goods_no){
        var return_amount = parseInt($('#input_amount_' + bill_goods_no).val());
        return_amount--;
        if( return_amount < 0 ){
            $('#input_amount_' + bill_goods_no).val(0);
            return;
        }else{
            $('#input_amount_' + bill_goods_no).val(return_amount);
        }

        this.amount--;
        this.calcAmount();
    },

    otherAmount:function(){

        this.dt = E.getFormValues('return_form');

        //计算积分的金额
        var points_amount = 0;
        if(typeof(this.dt.points) != "undefined"){
            points_amount = this.dt.points_amount/100;
        }

        //计算余额的金额
        var balance_amount = 0;
        if(typeof(this.dt.balance) != "undefined"){
            balance_amount = this.dt.balance_amount;
        }

        //计算优惠券的金额
        var coupon_amount = 0;
        if(typeof(this.dt.coupon_code_check) != "undefined"){
            $.each(this.dt.coupon_code_check,function(k,v){
                coupon_num = $("input[type=hidden][name='coupon_amount["+v+"][]']").val();
                coupon_amount = coupon_amount*1 + coupon_num*1;
            });
        }

        //计算现金卡的金额
        var card_amount = 0;
        if(typeof(this.dt.card_no_check) != "undefined"){
            $.each(this.dt.card_no_check,function(k,v){
                card_num = $("input[type=hidden][name='card_amount["+v+"][]']").val();
                card_amount = card_amount*1 + card_num*1;
            });
        }

        var totalOtherAmount = points_amount + balance_amount + coupon_amount + card_amount;

        return totalOtherAmount;
    },

    calcAmount : function(){

        this.price = 0;

        $.each(this.goods_array,function(name,value) {

            var return_amount = parseInt($('#input_amount_' + name).val());

            if(return_amount > 0)
            {
                bill.price += value.goods_purchasePrice * return_amount + value.buyMoney;
            }

        });

        if(this.amount == this.use_amount_total)
        {
            this.price = parseFloat(this.price) + parseFloat(this.deliver_feePaid);

        }

        this.dt = E.getFormValues('return_form');

        //计算积分的金额
        var points_amount = 0;
        if(typeof(this.dt.points) != "undefined"){

            if(this.dt.points != ''){
                points_amount = this.dt.points_amount/100;
            }else{
                points_amount = 0;
            }
        }else{
            points_amount = 0;
        }

        //计算余额的金额
        var balance_amount = 0;
        if(typeof(this.dt.balance) != "undefined"){
            if(this.dt.balance != ''){
                balance_amount = this.dt.balance_amount;
            }else{
                balance_amount = 0;
            }
        }else{
            balance_amount = 0;
        }

        //计算优惠券的金额
        var coupon_amount = 0;
        if(typeof(this.dt.coupon_code) != "undefined"){
            if(this.dt.coupon_code != ''){
                coupon_amount = 0;
                $.each(this.dt.coupon_code,function(k,v){
                    coupon_num = $("input[type=hidden][name='coupon_amount["+v+"][]']").val();
                    coupon_amount =coupon_amount*1 + coupon_num*1;
                });
            }else{
                coupon_amount = 0;
            }
        }else{
            coupon_amount = 0;
        }

        //计算现金卡的金额
        var card_amount = 0;
        if(typeof(this.dt.card_no) != "undefined"){
            if(this.dt.card_no != ''){
                card_amount = 0;
                $.each(this.dt.card_no,function(k,v){
                    card_num = $("input[type=hidden][name='card_amount["+v+"][]']").val();
                    card_amount =card_amount*1 + card_num*1;
                });
            }else{
                card_amount = 0;
            }
        }else{
            card_amount = 0;
        }

        if(this.bill_array.bill_status != 7){

            this.price -= this.otherAmount();
            this.price += points_amount + balance_amount + coupon_amount + card_amount;

        }else{

            this.price = this.price - points_amount - balance_amount - coupon_amount - card_amount;

        }

        if( this.price < 0 )
        {
            this.price=0;
        }

        this.price = this.price.toFixed(2);

        this.show();
    },

    save : function (){

        var error_msg = '';

        this.dt = E.getFormValues('return_form');

        if (this.dt.return_reason_id_1 == "") {
            error_msg += '请选择退货原因<br>';
        }

        if (this.dt.goods_return_type == 2) {
            if (this.dt.pick_provinceid == 0 || this.dt.pick_cityid == 0 || this.dt.pick_countyid == 0 || E.isEmpty(this.dt.pick_address)) {
                error_msg += '请完善取货地址<br>';
            }
        }

        if (E.isEmpty(this.dt.custName)) {
            error_msg += '联系人姓名不能为空<br>';
        }

        if (E.isEmpty(this.dt.mobile)) {
            error_msg += '手机号码不能为空<br>';
        }

        var goods_price = this.price;

        //计算积分的金额
        if(typeof(this.dt.points) != "undefined"){

            if(this.dt.points != ''){
                var points_amount = this.dt.points_amount/100;
            }else{
                var points_amount = 0;
            }
        }else{
            var points_amount = 0;
        }
        //计算余额的金额
        if(typeof(this.dt.balance) != "undefined"){
            if(this.dt.balance != ''){
                var balance_amount = this.dt.balance_amount;
            }else{
                var balance_amount = 0;
            }
        }else{
            var balance_amount = 0;
        }
        //计算优惠券的金额
        if(typeof(this.dt.coupon_code) != "undefined"){
            if(this.dt.coupon_code != ''){
                var coupon_amount = 0;
                $.each(this.dt.coupon_code,function(k,v){
                    coupon_num = $("input[type=hidden][name='coupon_amount["+v+"][]']").val();
                    coupon_amount =coupon_amount*1 + coupon_num*1;
                });
            }else{
                var coupon_amount = 0;
            }
        }else{
            var coupon_amount = 0;
        }


        //计算现金卡的金额
        var card_amount = 0;
        if(typeof(this.dt.card_no) != "undefined"){
            if(this.dt.card_no != ''){
                card_amount = 0;
                $.each(this.dt.card_no,function(k,v){
                    card_num = $("input[type=hidden][name='card_amount["+v+"][]']").val();
                    card_amount =coupon_amount*1 + card_num*1;
                });
            }else{
                card_amount = 0;
            }
        }else{
            card_amount = 0;
        }



        if(!E.isEmpty(this.dt.return_pay)){
            $.each(this.dt.return_pay, function(k, v){
                var returnPay = $.trim(v);
                if( !E.isEmpty(returnPay) &&  !E.isMoney(returnPay) ){
                    error_msg += "请输入正确的退货金额<br />";
                    return false;
                }

               // var return_money = parseFloat(returnPay*1 + points_amount*1 + balance_amount*1 + coupon_amount*1);

                var return_money = parseFloat(returnPay*1);

                if( return_money > parseFloat(goods_price) ){
                    error_msg += "退货金额不能大于商品金额<br />";
                    return false;
                }

            })
        }


        if (this.amount == 0) {
            error_msg += '请选择退货商品<br>';
        }


        var bill_code = $("input[name='bill_code']").val();

        var msg = "订单" + bill_code + "退货结果 <br />" ;
        msg += "1、退货金额：" + bill.price +"<br />";
        if((typeof(this.dt.card_no) != "undefined" && this.dt.card_no.length > 0) || (typeof(this.dt.points) != "undefined" && this.dt.points != '') || (typeof(this.dt.coupon_code) != "undefined" && this.dt.coupon_code.length > 0) || (typeof(this.dt.balance) != "undefined" && this.dt.balance != '' ))
        {
            msg += "2、";
            if(typeof(this.dt.card_no) != "undefined" && this.dt.card_no.length > 0)
            {
                msg += "订单支付的现金卡已勾选,将在退货单审核后重置";
                $.each(this.dt.card_no,function(key,value){
                    msg += "<br />" + value;
                });
                msg += "<br />";
            }

            if(typeof(this.dt.coupon_code) != "undefined" && this.dt.coupon_code.length > 0)
            {
                msg += "订单支付的优惠券已勾选,将在退货单审核后重置";
                $.each(this.dt.coupon_code,function(key,value){
                    msg += "<br />" + value;
                });
                msg += "<br />";
            }

            if(typeof(this.dt.points) != "undefined" && this.dt.points != '')
            {
                msg += "订单支付的积分已勾选,将在退货单审核后重置";
                msg += "<br />" + this.dt.points_amount;
                msg += "<br />";
            }

            if(typeof(this.dt.balance) != "undefined" && this.dt.balance != '' )
            {
                msg += "订单支付的余额已勾选,将在退货单审核后重置";
                msg += "<br />" + this.dt.balance_amount;
                msg += "<br />";
            }
        }




        if(typeof(this.dt.coupon_code) != "undefined" || typeof(this.dt.card_no) != "undefined" || typeof(this.dt.points) != "undefined" || typeof(this.dt.balance) != "undefined")
        {
            msg += "3、";

            if(typeof(this.dt.card_no) != "undefined")
            {
                $.each($("input[name='card_no']"),function(name,value){
                    msg += "订单支付的现金卡未勾选,将不可再使用";
                    if(!value.checked)
                    {
                        msg += "<br />" + value.value;
                    }
                    msg += "<br />";
                });
            }

            if(typeof(this.dt.coupon_code) != "undefined")
            {
                $.each($("input[name='coupon_code']"),function(name,value){
                    msg += "订单支付的优惠券未勾选,将不可再使用";
                    if(!value.checked)
                    {
                        msg += "<br />" + value.value;
                    }
                    msg += "<br />";
                });
            }


            if(typeof(this.dt.points) != "undefined" )
            {
                $.each($("input[name='points']"),function(name,value){
                    msg += "订单支付的积分未勾选,将不可再使用";
                    if(!value.checked)
                    {
                        msg += "<br />" + value.value;
                    }
                    msg += "<br />";
                });
            }

            if(typeof(this.dt.balance) != "undefined"  )
            {
                $.each($("input[name='balance']"),function(name,value){
                    msg += "订单支付的余额未勾选,将不可再使用";
                    if(!value.checked)
                    {
                        msg += "<br />" + value.value;
                    }
                    msg += "<br />";
                });
            }



        }




        if (error_msg != '') {
            E.alert(error_msg);
        }else if( this.identify == 1 && this.dt.return_pay == ""){
            E.confirm('您没有填写退款金额，确认要保存退货单吗？如果保存，订单结算会按正常订单金额结算', 'bill.confirmSave');
        }else {
            E.confirm( msg + '您确认要保存退货单吗？', 'bill.confirmSave');
        }

    },

    confirmSave : function (){

        E.loadding.open('正在保存退货单，请稍候...');
        E.ajax_post({
            url : "/invokingAjax-backend/bill/billReturn.ajax?operFlg=2",
            data : this.dt,
            call : function( o ) {
                E.loadding.close();
                if(o.code != 200){
                    E.alert(o.message);
                    return false;
                }
                E.alert("保存成功",2,"E.closeWindows");
            }
        });

    },

    //可退货的数量


    //显示底部金额及数量的数字
    show : function (){
        $("#return_amounts").text(this.amount);
        $("#return_prices").text(this.price);
        $("input[name='return_pay[]']").val(this.price);

    }
}

</script>
<script type="text/javascript" src="/framework/ebsig/js/item.js"></script>
<script type="text/javascript">
    get_second_item(14);
</script>
</body>
</html>